home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / NE2000.ASM < prev    next >
Assembly Source File  |  1992-01-10  |  7KB  |  297 lines

  1. version    equ    4
  2. ;History:56,1 0
  3.  
  4. ;  The following people have contributed to this code: David Horne, Eric
  5. ;  Henderson, and Bob Clements.
  6.  
  7. ;  Copyright, 1988-1992, Russell Nelson, Crynwr Software
  8.  
  9. ;   This program is free software; you can redistribute it and/or modify
  10. ;   it under the terms of the GNU General Public License as published by
  11. ;   the Free Software Foundation, version 1.
  12. ;
  13. ;   This program is distributed in the hope that it will be useful,
  14. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ;   GNU General Public License for more details.
  17. ;
  18. ;   You should have received a copy of the GNU General Public License
  19. ;   along with this program; if not, write to the Free Software
  20. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.     include    defs.asm
  23.  
  24. code    segment    word public
  25.     assume    cs:code, ds:code
  26.  
  27. ;*****************************************************************************
  28. ;
  29. ;    NE2000 controller board offsets
  30. ;    IO port definition (BASE in io_addr)
  31. ;*****************************************************************************
  32. NE_DATAPORT    EQU    10h        ; NE2000 Port Window.
  33. NE_RESET    EQU    1fh        ; Issue a read for reset
  34. EN_OFF        equ    0h
  35.  
  36.     include    8390.inc
  37.  
  38. ; Shared memory management parameters
  39.  
  40. SM_TSTART_PG    equ    040h    ; First page of TX buffer
  41. SM_RSTART_PG    equ    046h    ; Starting page of RX ring
  42. SM_RSTOP_PG    equ    080h    ; Last page +1 of RX ring
  43.  
  44. ram_enable    macro
  45.     endm
  46.  
  47. reset_8390    macro
  48.     loadport
  49.     setport    NE_RESET
  50.     in    al,dx
  51.     longpause
  52.     out    dx,al        ; should set command 21, 80
  53.  
  54.     endm
  55.  
  56. terminate_board    macro
  57.     endm
  58.  
  59.     public    int_no, io_addr
  60. int_no        db    2,0,0,0        ;must be four bytes long for get_number.
  61. io_addr        dw    0300h,0        ; I/O address for card (jumpers)
  62.  
  63.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  64. driver_class    db    BLUEBOOK, IEEE8023, 0        ;from the packet spec
  65. driver_type    dw    54        ;from the packet spec
  66. driver_name    db    'NE2000',0    ;name of the driver.
  67. driver_function    db    2
  68. parameter_list    label    byte
  69.     db    1    ;major rev of packet driver
  70.     db    9    ;minor rev of packet driver
  71.     db    14    ;length of parameter list
  72.     db    EADDR_LEN    ;length of MAC-layer address
  73.     dw    GIANT    ;MTU, including MAC headers
  74.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  75.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  76.     dw    0    ;(# of successive xmits) - 1
  77. int_num    dw    0    ;Interrupt # to hook for post-EOI
  78.             ;processing, 0 == none,
  79.  
  80. is_186        db    0
  81.  
  82. ;
  83. ;    Block input routine
  84. ;    CX = byte count, es:di = buffer location, ax = buffer address
  85.  
  86.     public    block_input
  87. block_input:
  88.     push    ax        ; save buffer address
  89.     loadport
  90.     setport EN_CCMD
  91.     pause_
  92.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  93.     out    dx,al
  94.     setport    EN0_RCNTLO    ; remote byte count 0
  95.     pause_
  96.     mov    al,cl
  97.     out    dx,al
  98.     setport    EN0_RCNTHI
  99.     pause_
  100.     mov    al,ch
  101.     out    dx,al
  102.     pop    ax        ; get our page back
  103.     setport    EN0_RSARLO
  104.     pause_
  105.     out    dx,al        ; set as hi address
  106.     setport    EN0_RSARHI
  107.     pause_
  108.     mov    al,ah
  109.     out    dx,al
  110.     setport EN_CCMD
  111.     pause_
  112.     mov    al,ENC_RREAD+ENC_START    ; read and start
  113.     out    dx,al
  114.     setport    NE_DATAPORT
  115.     pause_
  116.     cmp    is_186,0
  117.     jnz    read_186
  118. read_loop:
  119.     in    al,dx        ; get a byte
  120.     stosb            ; save it
  121.     loop    read_loop
  122.     ret
  123. read_186:
  124.     inc    cx        ; make even
  125.     shr    cx,1        ; word count
  126.     db    0f3h, 06dh    ;masm 4.0 doesn't grok "rep insw"
  127.     ret
  128. ;
  129. ;    Block output routine
  130. ;    CX = byte count, ds:si = buffer location, ax = buffer address
  131.  
  132. block_output:
  133.     assume    ds:nothing
  134.     push    ax        ; save buffer address
  135.     inc    cx        ; make even
  136.     and    cx,0fffeh
  137.     loadport
  138.     setport EN_CCMD
  139.     pause_
  140.     mov    al,ENC_NODMA+ENC_START
  141.     out    dx,al        ; stop & clear the chip
  142.     setport    EN0_RCNTLO    ; remote byte count 0
  143.     pause_
  144.     mov    al,cl
  145.     out    dx,al
  146.     setport    EN0_RCNTHI
  147.     pause_
  148.     mov    al,ch
  149.     out    dx,al
  150.     pop    ax        ; get our page back
  151.     setport    EN0_RSARLO
  152.     pause_
  153.     out    dx,al        ; set as lo address
  154.     setport    EN0_RSARHI
  155.     pause_
  156.     mov    al,ah
  157.     out    dx,al
  158.     setport EN_CCMD
  159.     pause_
  160.     mov    al,ENC_RWRITE+ENC_START    ; write and start
  161.     out    dx,al
  162.     setport    NE_DATAPORT
  163.     pause_
  164.     cmp    byte ptr is_186,0
  165.     jnz    write_186
  166. write_loop:
  167.     lodsb            ; get a byte
  168.     out    dx,al        ; save it
  169.     loop    write_loop
  170.     jmp    short block_output_1
  171. write_186:
  172.     shr    cx,1        ; word count
  173.     db    0f3h, 06fh    ;masm 4.0 doesn't grok "rep outsw"
  174. block_output_1:
  175.     mov    cx,0
  176.     setport    EN0_ISR
  177. tx_check_rdc:
  178.     in    al,dx
  179.     test    al,ENISR_RDC    ; dma done ???
  180.     jnz    tx_start
  181.     loop    tx_check_rdc
  182.     stc
  183.     ret
  184. tx_start:
  185.     clc
  186.     ret
  187.  
  188.  
  189.     include    8390.asm
  190.  
  191.     public    usage_msg
  192. usage_msg    db    "usage: NE2000 [-n] [-d] [-w] <packet_int_no> <int_level> <io_addr>",CR,LF,'$'
  193.  
  194.     public    copyright_msg
  195. copyright_msg    db    "Packet driver for NE2000, version "
  196.         db    '0'+majver,".",'0'+version,".",'0'+dp8390_version,CR,LF,'$'
  197.  
  198. int_no_name    db    "Interrupt number ",'$'
  199. io_addr_name    db    "I/O port ",'$'
  200.  
  201.     extrn    set_recv_isr: near
  202.  
  203. ;enter with si -> argument string, di -> word to store.
  204. ;if there is no number, don't change the number.
  205.     extrn    get_number: near
  206.  
  207. ;enter with dx -> name of word, di -> dword to print.
  208.     extrn    print_number: near
  209.  
  210.     public    parse_args
  211. parse_args:
  212. ;exit with nc if all went well, cy otherwise.
  213.     mov    di,offset int_no
  214.     call    get_number
  215.     mov    di,offset io_addr
  216.     call    get_number
  217.     clc
  218.     ret
  219.  
  220.     extrn    etopen_diagn: byte
  221.  
  222. init_card:
  223. ;get the board data. This is (16) bytes starting at remote
  224. ;dma address 0. Put it in a buffer called board_data.
  225.     assume    ds:code
  226.  
  227.     or    endcfg,ENDCFG_WTS
  228.  
  229.     loadport
  230.     mov    al,endcfg
  231.     setport    EN0_DCFG
  232.     pause_
  233.     out    dx,al
  234.  
  235.     mov    cx,10h        ; get 16 bytes,
  236.     push    ds
  237.     pop    es        ; set es to ds
  238.     mov    di,offset board_data
  239.  
  240.     setport EN_CCMD
  241.     pause_
  242.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  243.     out    dx,al
  244.     setport    EN0_RCNTLO    ; remote byte count 0
  245.     pause_
  246.     mov    al,20h        ; count is actually doubled.
  247.     out    dx,al
  248.     setport    EN0_RCNTHI
  249.     pause_
  250.     xor    al,al        ; high byte of count is zero.
  251.     out    dx,al
  252.  
  253.     mov    ax,0        ; from address 0
  254.  
  255.     setport    EN0_RSARLO
  256.     pause_
  257.     out    dx,al        ; set as hi address
  258.     setport    EN0_RSARHI
  259.     pause_
  260.     mov    al,ah
  261.     out    dx,al
  262.     setport EN_CCMD
  263.     pause_
  264.     mov    al,ENC_RREAD+ENC_START    ; read and start
  265.     out    dx,al
  266.     setport    NE_DATAPORT
  267.     pause_
  268. sp_read_loop:
  269.     in    al,dx        ; get a byte
  270.     stosb            ; save it
  271.     loop    sp_read_loop
  272.  
  273.     push    ds              ; Copy from card's address to current address
  274.     pop     es
  275.  
  276.     mov si, offset board_data    ; address is at start
  277.     mov di, offset curr_hw_addr
  278.     mov cx, EADDR_LEN       ; Copy one address length
  279.     rep     movsb           ; ..
  280.  
  281.     ret
  282.  
  283.     public    print_parameters
  284. print_parameters:
  285. ;echo our command-line parameters
  286.     mov    di,offset int_no
  287.     mov    dx,offset int_no_name
  288.     call    print_number
  289.     mov    di,offset io_addr
  290.     mov    dx,offset io_addr_name
  291.     call    print_number
  292.     ret
  293.  
  294. code    ends
  295.  
  296.     end
  297.